草庐IT

sqlite - Symfony2 : Unit testing with sqlite

全部标签

php - Symfony2 表格数组?

是否可以创建和呈现我知道的关于集合的表单数组,但它们并不真正符合我的想法?我想要的是这样的Controller$data=$em->findAll();$Forms=$this->createForm(newSomeType,$data);return$this->render(someView,array("Forms"=>$Forms->createView()));Twig{%forForminForms%}{{form(Form)}}{%endfor%} 最佳答案 只需在数组中创建表单:$data=$em->findAll(

php - Symfony2 ajax 表单验证在 Twig 中呈现错误

我在Symfony2中有一个表单,我用ajax验证它。这一切正常,我在ajax调用的成功声明中得到了一个带有“全局”(用于全局错误)和“字段”(此处每个字段的错误)的json:{"global":[],"fields":{"fos_user_registration_form_username":"Pleaseenterausername","fos_user_registration_form_email":"Pleaseenteranemail","fos_user_registration_form_plainPassword_first":"Pleaseenterapasswo

php - 如何在 Symfony 中手动调度 Doctrine/Kernel 事件?

我需要手动发送一个preRemove事件,因为我正在软删除一个实体,因此并没有真正删除它。但是,我想在实际删除实体时触发相同的监听器。我可以像自定义事件那样使用EventDispatcher(不需要LifecycleEventArgs)吗?发送原版事件的最佳方式是什么?编辑:感谢bosam的回答,这是手动发送原版事件的方法:useDoctrine\ORM\Event\LifecycleEventArgs;useDoctrine\ORM\Events;$em=$this->getDoctrine()->getManager();$eventManager=$em->getEventMan

php - Symfony 找不到模板文件

我已按照与Symfony安装相关的所有步骤进行操作,并尝试了Symfony书中的示例(由Symfony网站提供)。目前我在Controller第(5)章,我尝试以下代码:namespaceMyBundle\FrontBundle\Controller;useSymfony\Bundle\FrameworkBundle\Controller\Controller;useSymfony\Component\HttpFoundation\Request;useSymfony\Component\HttpFoundation\Response;classHelloControllerexten

php - Symfony2.7.1 全新安装。无法加载资源

Symfony2开发人员:最近打算熟悉一下Symfony2,把它作为api项目。当前版本为v2.7.1。我已经安装了apache作为我的本地环境。所以安装根目录为://本地主机/symfony所以我按照官方指南安装了它。安装后一切看起来都很好。但是当我在开发环境(app_dev.php)中查看页面时。//localhost/symfony/web/app_dev.php页面内容按预期显示,但未设置样式。然后我打开控制台,发现一些404响应如下:Failedtoloadresource//localhost/symfony/web/bundles/framework/css/struct

php - 如何在 symfony 中将 404 重定向到主页?

我想重定向这个urlhttp://www.businessbid.ae/stagging/web/feedback至http://www.businessbid.ae。我能做什么? 最佳答案 您应该创建一个监听器来监听onKernelExceptionEvent。因为您可以检查404状态代码并设置重定向响应。AppBundle\EventListener\Redirect404ToHomepageListenernamespaceAppBundle\EventListener;useSymfony\Component\HttpKer

php - Symfony 3 文件上传

我正在尝试使用Symfony3为我的应用程序实现文件上传功能。我有一个产品条目,与文件条目有关。部分产品:/***@ORM\OneToMany(targetEntity="AppBundle\Entity\File",mappedBy="product")*@ORM\OrderBy({"weight"="DESC"})*/protected$files;和表单上的字段:->add('files',FileType::class,array('multiple'=>true,'data_class'=>'AppBundle\Entity\File'));publicfunctioncon

php - Symfony 3 中 FilesystemAdapter 的默认缓存目录在哪里?

我在Windows上寻找由FileSystemAdapter生成的缓存的位置。我以为它会在应用程序目录的var/cache中,但它看起来不像我清除它时那样,它仍在使用缓存。知道它可能在哪里吗? 最佳答案 FilesystemCacheAdapteruseSymfony\Component\Cache\Adapter\FilesystemAdapter;$cache=newFilesystemAdapter(//thesubdirectoryofthemaincachedirectorywherecacheitemsarestored

php - Symfony:动态更改数据库

假设我有3个数据库:prefix_db1prefix_db2prefix_db3我想从这样的url动态连接到它们http://localhost/my-project/web/app_dev.php/db1/books所以我知道要连接到哪个数据库来自url(在本例中为prefix_db1)基本上,我们的想法是准备一个监听器,它将随每个http请求一起触发,从url中获取数据库名称,然后覆盖doctrin的参数,如下所示:在services.yml中:dynamic_connection:class:AppBundle\service\DynamicDBConnectorargument

php - 如何使用 Symfony 将一组数据保存在 cookie 中?

首先,我对cookie不是很熟悉,但我知道它们的工作原理。我看过许多使用纯PHP代码的不同教程,但我正在寻找一个关于如何使用symfony语法将数组存储在cookie中的可靠示例:$this->getResponse()->setCookie('myCookie',$data);你不能只传入一个数组,因为它需要一个字符串。唯一的方法是先序列化一个数组吗?在将数据存储在cookie中时还有其他选择吗? 最佳答案 如果你真的需要将它存储在cookie中而不是在session中,你可以使用序列化:$this->getResponse()-